<?php

// 商品属性表

namespace app\client\model;

use think\Model;
use think\Request;
use app\client\model\ShopGoodsSpec as ShopGoodsSpecModel;
use app\client\model\ShopGoodsAttr as ShopGoodsAttrModel;
use think\Session;

class ShopGoodsSpec extends Model
{
    // 模型事件
    protected static function init()
    {

        self::event('before_write', function ($data) {
            auding($data);
        });
    }
    public function getAudingTextAttr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status']];
    }

    public function getAudingText1Attr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status1']];
    }
    public function getAudingText2Attr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status2']];
    }
    public function getAudingText3Attr($value, $data)
    {
        $status = [1 => '等待审核', 2 => '审核成功', 3 => '审核失败'];
        return $status[$data['auding_status3']];
    }

    // 删除方法
    public static function amputate($id)
    {

        if ((new ShopGoodsSpecModel())->destroy($id)) {

            (new ShopGoodsAttrModel)->where(['spec_id' => $id])->delete();

            return true;
        }

        return false;

    }

    // 全部删除方法
    public static function amputateAll($id)
    {

        foreach ($id as $value) {
            (new ShopGoodsAttrModel)->where(['spec_id' => $value])->delete();
        }

        return true;

    }
}